import request from "./request";

// 登录请求
export function loginApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/api/login", data, {
    headers: {
      "Content-type": "application/json",
    }
  }).then(resolve).catch(reject);
}

// 获取基础信息
export function getInfoApi(resolve = () => { }, reject = () => { }) {
  request.get("/userinfo/getInfo", {
    headers: {
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 获取收货信息
// /userinfo/getAddressee
export function getAddresseeApi(resolve = () => { }, reject = () => { }) {
  request.get("/userinfo/getAddressee", {
    headers: {
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 用户注册
export function registerApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/api/register", data, {
    headers: {
      "Content-type": "application/json",
    }
  }).then(resolve).catch(reject);
}

// 修改昵称
// /userinfo/updateNick
export function updateNickApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/userinfo/updateNick", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 修改密码
// /userinfo/updatePwd
export function updatePwdApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/userinfo/updatePwd", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 修改地址
// /userinfo/updateAddr
export function upAddresseeApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/userinfo/updateAddr", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 修改头像
// /userinfo/updatePort
export function updatePortApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/userinfo/updatePort", data, {
    headers: {
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 获取所有商品列表
export function getListApi(resolve = () => { }, reject = () => { }, params) {
  request.get("/goods/getList", {
    params: params,
    headers: {}
  }).then(resolve).catch(reject);
}

// 获取商品分类
// /getType/getTypeList
export function getTypeApi(resolve = () => { }, reject = () => { }) {
  request.get("/getType/getTypeList", {
    headers: {
    }
  }).then(resolve).catch(reject);
}

// 通过商品分类获取商品
// /goods/getByType
export function getByTypeApi(resolve = () => { }, reject = () => { }, params) {
  request.get("/goods/getByType", {
    params: params,
    headers: {
    }
  }).then(resolve).catch(reject);
}

// 通过商品名称获取商品
// /goods/getByName
export function getByNameApi(resolve = () => { }, reject = () => { }, params) {
  request.get("/goods/getByName", {
    params: params,
    headers: {
    }
  }).then(resolve).catch(reject);
}


// 通过商品 id 获取商品详情
// /goods/getById
export function getByIdApi(resolve = () => { }, reject = () => { }, params) {
  request.get("/goods/getById", {
    params: params,
    headers: {
    }
  }).then(resolve).catch(reject);
}


// 获取热销商品
// /goods/getByHot
export function getByHotApi(resolve = () => { }, reject = () => { }) {
  request.get("/goods/getByHot", {
    headers: {
    }
  }).then(resolve).catch(reject);
}

// 获取新品
// /goods/getByTime
export function getByTimeApi(resolve = () => { }, reject = () => { }) {
  request.get("/goods/getByTime", {
    headers: {
    }
  }).then(resolve).catch(reject);
}

// 获取购物车列表
// /shoppingCart/getCart
export function getCartApi(resolve = () => { }, reject = () => { }) {
  request.get("/shoppingCart/getCart", {
    headers: {
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 移出购物车
// /shoppingCart/removeCart
export function removeCartApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/shoppingCart/removeCart", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 加入购物车
// /shoppingCart/addToCart
export function addToCartApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/shoppingCart/addToCart", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

//  修改购物车商品数量
// /shoppingCart/upAmount
export function upAmountApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/shoppingCart/upAmount", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 添加订单
// /order/addOrder
export function addOrderApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/order/addOrder", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 获取订单列表
// /order/getOrder
export function getOrderApi(resolve = () => { }, reject = () => { }) {
  request.get("/order/getOrder", {
    headers: {
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 修改订单状态
// /order/upState
export function upStateApi(resolve = () => { }, reject = () => { }, data) {
  request.post("/order/upState", data, {
    headers: {
      "Content-type": "application/json",
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 获取购物车长度
// /shoppingCart/getLen
export function getCartLenApi(resolve = () => { }, reject = () => { }) {
  request.get("/shoppingCart/getLen", {
    headers: {
      'Authorization': localStorage.getItem("token"),
    }
  }).then(resolve).catch(reject);
}

// 获取 banner 图片
// /banner/getBanner
export function getBannerApi(resolve = () => { }, reject = () => { }) {
  request.get("/banner/getBanner", {
    headers: {
    }
  }).then(resolve).catch(reject);
}